<?php namespace Common\Model;
use Hdphp\Model\Model;
class Member extends Model{
	//指定表名
	protected $table="user";
	//自动完成
	protected $auto=[
		['password','md5','function',3,3],
		['repassword','md5','functoin',3,3]
	];
	//自动验证
	 protected $validate=[
		['code','required','验证码不能为空',3,3],
		['username','required','请输入用户名',3,3],
        ['password','required','请输入密码',3,3],
        ['repassword','required','请输入再次密码',3,3],
        ['nickname','required','请输入昵称',3,3],
		['code','_code','验证码输入错误',3,3],
		['username','/^[\d\w]{2,14}$/','用户名输入错误',3,3],
		['password','minlen:6;','密码不能少于6位',3,3],
        ['password','_password','两次密码输入不一致',3,3],
		['username','_username','用户名已存在',3,3]
	];
	//自定义验证函数
	public function _code(){
		$code=Q('post.code');
		if(strtolower($code)!=strtolower($_SESSION['code'])){
			return FALSE;
		}
		return TRUE;
	}
	public function _password(){
	    if(Q('post.password')!=Q('post.repassword')){
	    	return FALSE;
	    }
		return TRUE;
	}
	public function _username(){
		$username=Q('post.username');
		$username=$this->where("username='{$username}'")->find();
		if($username){
			return	FALSE;
		}
		return TRUE;
	}
	//注册
	public function store(){
	if(!$this->create()) return FALSE;	
	return $this->add();
	}	
	
}

 ?>